<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>Dump Viewer</title>
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles.css') }}">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="http://marvl.infotech.monash.edu/webcola/cola.min.js"></script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script>
<script src="{{url_for('static', filename='pipeline_viewer.js')}}"></script> 
</head>

<body>
    <a href="../index.html">cola.js home</a>
<h1>Kotekan Pipeline</h1>
<div class="dropdown">
    <button onclick="onclick_cb()" class="dropbtn">Select a file</button>
    <div id="file_dropdown" class="dropdown-content"></div>
</div>
<div class="slidecontainer">
    <input type="range" min="0" max="100" step="0.01" value="100" class="slider" id="slide_input">
    <p>time: <span id="slide_value"></span></p>
</div>

<script>
    function onclick_cb() {
        document.getElementById("file_dropdown").classList.toggle("show");
    }

    // Close the dropdown if the user clicks outside of it
    window.onclick = function(event) {
        if (!event.target.matches('.dropbtn')) {
            var dropdowns = document.getElementsByClassName("dropdown-content");
            var i;
            for (i = 0; i < dropdowns.length; i++) {
                var openDropdown = dropdowns[i];
                if (openDropdown.classList.contains('show')) {
                    openDropdown.classList.remove('show');
                }
            }
        }
    }

    // Load file menu
    get_data("/dump_dir").then(function (files) {
        var div = document.getElementById("file_dropdown");
        var file_names = d3.select(div).selectAll(".choice")
            .data(files)
            .enter().append("p");

        // Only show files without folder name
        file_names.each(function(d) {
            this.innerHTML = d.replace("/dump_dir/", "");
            this.setAttribute("id", d);

            // Click on a new file will retrigger pipeline drawing
            this.addEventListener("click", function(event) {
                var endpoint = event.target.getAttribute("id");
                get_data(endpoint).then(function(data) {
                    pipeline = new PipelineViewer(data[0], d3.select("body"), data[1]);
                    pipeline.start_viewer();
                })
            });
        })
    })

</script>
</body>
</html>
